﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 自定义关闭最小化按钮
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_Minisize_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_Close_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 拖动窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
        /// <summary>
        /// 鼠标进入最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_Minisize_MouseEnter(object sender, MouseEventArgs e)
        {
            var imagePath = Directory.GetCurrentDirectory()+"\\Images\\minisize-active.png";
            ChangeHeaderImage(imagePath, img_Minisize);
        }
        /// <summary>
        /// 鼠标进入关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_Close_MouseEnter(object sender, MouseEventArgs e)
        {
            var imagePath = Directory.GetCurrentDirectory()+"\\Images\\close-active.png";
            ChangeHeaderImage(imagePath, img_Close);
        }
        /// <summary>
        /// 鼠标离开最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_Minisize_MouseLeave(object sender, MouseEventArgs e)
        {
            var imagePath = Directory.GetCurrentDirectory()+"\\Images\\minisize.png";
            ChangeHeaderImage(imagePath, img_Minisize);
        }
        /// <summary>
        /// 鼠标离开关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_Close_MouseLeave(object sender, MouseEventArgs e)
        {
            var imagePath = Directory.GetCurrentDirectory()+"\\Images\\close.png";
            ChangeHeaderImage(imagePath, img_Close);
        }
        private void ChangeHeaderImage(string imagePath, Image image)
        {
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(imagePath, UriKind.Absolute);
            bi.EndInit();
            image.Source = bi;
        }
    }
}
